home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Examples / Embed / Sources / EmbedPar.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  5.3 KB  |  188 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                EmbedPar.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Author:                M.Boetcher
  7. //
  8. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "Embed.hpp"
  13.  
  14. #ifndef EMBEDPART_H
  15. #include "EmbedPar.h"
  16. #endif
  17.  
  18. #ifndef EMBEDDEF_H
  19. #include "EmbedDef.h"
  20. #endif
  21.  
  22. #ifndef EMBEDSEL_H
  23. #include "EmbedSel.h"
  24. #endif
  25.  
  26. #ifndef EMBEDPROXY_H
  27. #include "EmbedPxy.h"
  28. #endif
  29.  
  30. #ifndef EMBEDFRAME_H
  31. #include "EmbedFra.h"
  32. #endif
  33.  
  34. // ----- OS Layer -----
  35.  
  36. #ifndef FWSUSINK_H
  37. #include "FWSUSink.h"
  38. #endif
  39.  
  40. #ifndef FWCFMRES_H
  41. #include "FWCFMRes.h"
  42. #endif
  43.  
  44. // ----- OpenDoc Includes -----
  45.  
  46. #ifndef SOM_Module_OpenDoc_Commands_defined
  47. #include <CmdDefs.xh>
  48. #endif
  49.  
  50. #ifndef SOM_Module_OpenDoc_StdProps_defined
  51. #include <StdProps.xh>
  52. #endif
  53.  
  54. //========================================================================================
  55. //    Runtime information
  56. //========================================================================================
  57.  
  58. #ifdef FW_BUILD_MAC
  59. #pragma segment odfembed
  60. #endif
  61.  
  62. //========================================================================================
  63. //    CLASS CEmbedPart
  64. //========================================================================================
  65.  
  66. const ODValueType CEmbedPart::kPartKind = kODFEmbedKind;
  67. const ODValueType CEmbedPart::kPartUserName = kODFEmbedEditorUserString;
  68.  
  69. #define kMainPresentation "Apple:Presentation:EmbedPart"
  70.  
  71. //----------------------------------------------------------------------------------------
  72. //     CEmbedPart constructor
  73. //----------------------------------------------------------------------------------------
  74.  
  75. CEmbedPart::CEmbedPart(ODPart* odPart):
  76.     FW_CEmbeddingPart(odPart, CEmbedPart::kPartKind, CEmbedPart::kPartUserName, FW_gInstance, kPartIconID),
  77.     fSelection(NULL),
  78.     fPresentation(NULL),
  79.     fProxy(NULL)
  80. {
  81.     // Do not call anything that can fail
  82. }
  83.  
  84. //----------------------------------------------------------------------------------------
  85. //     CEmbedPart::Initialize
  86. //----------------------------------------------------------------------------------------
  87.  
  88. void CEmbedPart::Initialize(Environment* ev)
  89. {
  90.     FW_CEmbeddingPart::Initialize(ev);
  91.  
  92.     fSelection = new CEmbedSelection(ev, this);    // actually owned by the presentation
  93.     fPresentation = RegisterPresentation(ev, kMainPresentation, TRUE, fSelection);
  94. }
  95.  
  96. //----------------------------------------------------------------------------------------
  97. //     CEmbedPart destructor
  98. //----------------------------------------------------------------------------------------
  99.  
  100. CEmbedPart::~CEmbedPart()
  101. {
  102.     if (fProxy)
  103.     {
  104.         delete fProxy;
  105.         fProxy = NULL;
  106.     }
  107.  
  108.     //     Notice that I don't delete the selection object. 
  109.     //    It is owned by the presentation object
  110. }
  111.  
  112. //----------------------------------------------------------------------------------------
  113. //    CEmbedPart::ExternalizeContent
  114. //----------------------------------------------------------------------------------------
  115.  
  116. void CEmbedPart::ExternalizeContent(Environment* ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
  117. {
  118.     ODValueType contentPropertyValueType = this->GetPartKind(ev);
  119.     storageUnit->Focus(ev, kODPropContents, kODPosUndefined, contentPropertyValueType, 0, kODPosUndefined);
  120.     storageUnit->Remove(ev);
  121.     storageUnit->AddValue(ev, contentPropertyValueType);
  122.     
  123.     // ----- Create an archive -----
  124.     FW_CStorageUnitSink sink(storageUnit, kODPropContents, contentPropertyValueType);
  125.     FW_CWritableStream archive(&sink);
  126.     
  127.     // ----- Write number of embedded parts -----
  128.     unsigned long count = 0;
  129.     if (fProxy)
  130.         count = 1;
  131.     archive << count;
  132.     
  133.     // ----- Write embedded part -----
  134.     if (fProxy)
  135.         fProxy->Externalize(ev, sink.GetStorageUnitView(), cloneInfo);
  136. }
  137.  
  138. //----------------------------------------------------------------------------------------
  139. //    CEmbedPart::InternalizeContent
  140. //----------------------------------------------------------------------------------------
  141.  
  142. void CEmbedPart::InternalizeContent(Environment *ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
  143. {
  144.     // ----- Create an archive -----
  145.     FW_CStorageUnitSink sink(storageUnit, kODPropContents, this->GetPartKind(ev));
  146.     FW_CReadableStream archive(&sink);
  147.     
  148.     // ----- Read number of embedded parts -----
  149.     unsigned long count;
  150.     archive >> count;
  151.     
  152.     // ----- Read embedded part, if any -----
  153.     if (count == 1)
  154.     {
  155.         fProxy = new CEmbedProxy(ev, this);
  156.         fSelection->SetProxy(ev, fProxy);
  157.         fProxy->Internalize(ev, sink.GetStorageUnitView(), cloneInfo);
  158.     }    
  159. }
  160.  
  161. //----------------------------------------------------------------------------------------
  162. //     CEmbedPart::NewFrame
  163. //----------------------------------------------------------------------------------------
  164.  
  165. FW_CFrame* CEmbedPart::NewFrame(Environment* ev, 
  166.                                 ODFrame* odFrame, 
  167.                                 FW_CPresentation* presentation, 
  168.                                 FW_Boolean fromStorage)
  169. {
  170. FW_UNUSED(presentation);
  171. FW_UNUSED(fromStorage);
  172.     
  173.     return new CEmbedFrame(ev, odFrame, presentation, this);
  174. }
  175.  
  176. //----------------------------------------------------------------------------------------
  177. //    CEmbedPart::SetProxy
  178. //----------------------------------------------------------------------------------------
  179.  
  180. void CEmbedPart::SetProxy(Environment* ev, CEmbedProxy* proxy)
  181. {    
  182.     fProxy = proxy;
  183.         
  184.     // a proxy is always selected 
  185.     fSelection->SetProxy(ev, proxy);
  186. }
  187.  
  188.